<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<!-- import CSS -->
	<script src="../../js/commonCss.js"></script>
	<title>附加险管理</title>
</head>
<body>
<div id="app" v-cloak>
	<div class="pd10 border-bottom ft-14 h40">
		附加险管理
		<el-button class="f-r" type="primary" icon="el-icon-plus" @click="addCont">添加附加险</el-button>
	</div>
	<div class="pd10">
		<el-form :inline="true" :model="formInline" class="demo-form-inline">
			<el-form-item>
				<el-input v-model="formInline.title" type="text" placeholder="产品名称"></el-input>
			</el-form-item>
<!--			<el-form-item>-->
<!--				<el-select v-model="formInline.category" placeholder="产品类别">-->
<!--					<el-option :label="item.label" :value="item.value" v-for="item in categoryArr" :key="item.label"></el-option>-->
<!--				</el-select>-->
<!--			</el-form-item>-->
			<el-form-item>
				<el-select v-model="formInline.com" placeholder="保险公司">
					<el-option :label="item.icTitle" :value="item.icId" v-for="item in companyArr" :key="item.icTitle"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="search">查询</el-button>
			</el-form-item>
		</el-form>
		<el-table :data="tableData" stripe border style="width: 100%" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55">
			</el-table-column>
			<el-table-column prop="iaTitle" label="产品名称"></el-table-column>
			<el-table-column prop="iaComm" label="保险公司"></el-table-column>
			<el-table-column label="操作">
				<template slot-scope="scope">
					<el-button @click="handleEdit(scope.row)" type="text" size="medium">编辑</el-button>
					<el-button @click="handleDelete(scope.row)" type="text" size="medium" class="color-F56C6C">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!-- 分页 -->
		<div class="bottomstate">
			<el-button type="danger" @click="batchDelete">批量删除</el-button>
			<el-pagination class="f-r mt5" background @current-change="handleCurrentChange" :current-page="page" :page-size="limit" layout="total,prev, pager, next,jumper"
						   :total="total" ></el-pagination>
		</div>
	</div>
</div>
</body>
<script src="/jeefast/elementui-lib/lib/vue.js"></script>
<script src="/jeefast/elementui-lib/lib/index.js"></script>
<script src="/jeefast/js/jquery-1.9.1.min.js"></script>
<script src="/jeefast/js/axios.js"></script>
<script src="/jeefast/js/data.js"></script>
<script>
	var app = new Vue({
		el: "#app",
		mixins: [mix],
		data: function() {
			return {
				formInline:{
					title:"",
					com:""
				},
				// 全选
				multipleSelection: [],
				categoryArr:[],
				companyArr: [],
				tableData: [{
					id:1,
					name:"无豁免重大疾病险",
					company:"中国人寿",
				},{
					id:2,
					name:"无豁免重大疾病险",
					company:"百年人寿",
				}],
			}
		},
		methods: {
			search:function(){
				let that = this;
				//获取附加险
				additionalList({page: this.page, //起始页面
					limit: this.limit, //每页显示个数
					title:this.formInline.title,
					com:this.formInline.com
				}).then(res=>{
					if(res.data.code==0){
						that.tableData = res.data.data;
						console.log("+++++")
						console.log(res.data.data)
					}
					//循环
					for (let i = 0; i <that.tableData.length ; i++) {
						console.log(that.tableData[i].iaComm)
						companyById({comId:that.tableData[i].iaComm}).then(res=>{
							that.tableData[i].iaComm = res.data.data.icTitle ;
						})
					}
					console.log(that.tableData)
				})
			},
			// 添加
			addCont:function(){
				window.location.href = 'additionalRisksCont.html';//此处拼接内容
			},
			// 删除
			handleDelete:function(row){
				let that = this
				that.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					deleteAdditional({ids:row.iaId}).then(res=>{
						if(res.data.code==0){
					that.$message({
						type: 'success',
						message: '删除成功!'
					});
					//获取附加险
					additionalList({page: this.page, //起始页面
						limit: this.limit, //每页显示个数
					}).then(res=>{
						if(res.data.code==0){
						that.tableData = res.data.data;
						console.log("+++++")
						console.log(res.data.data)
					}
					//循环
					for (let i = 0; i <that.tableData.length ; i++) {
						console.log(that.tableData[i].iaComm)
						companyById({comId:that.tableData[i].iaComm}).then(res=>{
							that.tableData[i].iaComm = res.data.data.icTitle ;
					})
					}
					console.log(that.tableData)
				})
				}
			})
			}).catch(() => {
					that.$message({
						type: 'info',
						message: '已取消删除'
					});
			});
			},
			// 批量删除
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			//获取保险公司
			getComp(){
				let that = this;
				companyList({limit:1000}).then(res=>{
					that.companyArr = res.data.data
					console.log("111")
					console.log(that.companyArr)
				})
			},
			batchDelete() {
				let that = this
				let ids = []
				if (that.multipleSelection.length>0) {
					that.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						for(let i=0;i<that.multipleSelection.length;i++){
							console.log(that.multipleSelection[i].iaId);
						ids.push(that.multipleSelection[i].iaId)
					}
					deleteAdditional({ids:ids.join(',')}).then(res=>{
						if(res.data.code==0){
						that.$message({
							type: 'success',
							message: '删除成功!'
						});
                        that.getTable();
					}
				})
				}).catch(() => {
						that.$message({
							type: 'info',
							message: '已取消删除'
						});
				});
				} else {
					that.$message({
						type: 'warning',
						message: '请选择需要删除的数据'
					});
				}
			},
			handleEdit:function(row){
				console.log(row)
				window.location.href = 'additionalRisksCont.html?id='+row.iaId;//此处拼接内容
			},
            getTable(){
                let that = this;
                //获取附加险
                additionalList({page: this.page, //起始页面
                    limit: this.limit, //每页显示个数
                }).then(res=>{
                    if(res.data.code==0){
                    that.tableData = res.data.data;
                    console.log("+++++")
                    console.log(res.data.data)
                }
                //循环
                for (let i = 0; i <that.tableData.length ; i++) {
                    console.log(that.tableData[i].iaComm)
                    companyById({comId:that.tableData[i].iaComm}).then(res=>{
                        that.tableData[i].iaComm = res.data.data.icTitle ;
                })
                }
                console.log(that.tableData)
            })
            },
		},
		created() {
			let that = this;
			//获取保险公司
			that.getComp();
			//获取附加险
			additionalList({page: this.page, //起始页面
				limit: this.limit, //每页显示个数
			}).then(res=>{
				if(res.data.code==0){
					that.tableData = res.data.data;
					console.log("+++++")
					console.log(res.data.data)
				}
				//循环
				for (let i = 0; i <that.tableData.length ; i++) {
					console.log(that.tableData[i].iaComm)
					companyById({comId:that.tableData[i].iaComm}).then(res=>{
						that.tableData[i].iaComm = res.data.data.icTitle ;
					})
				}
				console.log(that.tableData)
			})
		},
	});
</script>
</html>
